package com.szt.mobile.inventory.common.biz;

import android.os.AsyncTask;

/**
 * Created by yanzhaodi on 2017/9/14.
 */

public abstract class CustomAsynTask<Request, Response> extends AsyncTask<Request, Void, Response> {

    protected abstract Response doJob(Request request);
    protected abstract void doCancel();

    private AsynResult<Response> asynResult;

    public CustomAsynTask(AsynResult<Response> asynResult) {
        this.asynResult = asynResult;
    }

    @Override
    protected Response doInBackground(Request[] requests) {
        if (requests.length == 0) {
            return doJob(null);
        }
        return doJob(requests[0]);
    }

    @Override
    protected void onPostExecute(Response response) {
        if (null != asynResult) {
            asynResult.result(response);
        }
    }

    public interface AsynResult<Response> {
        void result(Response response);
    }
}
